package com.gxar.quick.ar.server.base.controller;

import com.gxar.common.entity.Result;
import com.gxar.common.warning.ApiLog;
import com.gxar.quick.ar.server.base.facade.PayFacade;
import com.gxar.quick.ar.server.base.model.pay.vo.request.WechatNotifyRequest;
import com.gxar.quick.ar.server.base.model.pay.vo.response.WechatTransactionResponse;
import com.gxar.quick.ar.server.base.sdk.WechatPaySDK;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author nice
 * @version 1.0
 * @created 2023/11/11.
 */
@Api(tags = "支付接口")
@RestController
@RequestMapping("/api/pay")
@RequiredArgsConstructor
@Slf4j
public class PayController {

    private final WechatPaySDK wechatPaySDK;
    private final PayFacade payFacade;

    @ApiOperation("微信支付回调接口")
    @PostMapping("/wechat/notify")
    @ApiLog
    public Result wechatNotify(@RequestBody WechatNotifyRequest request) {
        payFacade.notify(request);
        return Result.success();
    }

    @ApiOperation("微信支付单查询")
    @GetMapping("/wechat/transaction")
    public Result<WechatTransactionResponse> transaction(@RequestParam String orderId) {
        WechatTransactionResponse result = wechatPaySDK.queryTransaction(orderId);
        return Result.success(result);
    }
}
